package com.example.androidmqtt.Vo;

import lombok.Data;

/**
 * @author: pjg
 * @time: 2022/9/13
 */
@Data
public class ResultData<T> {

    private static final Integer CODE_SUCCESSFUL = 200;
    private static final Integer CODE_FAILURE = 400;

    private Integer code;
    private String msg;

    private Integer dataCount;

    private T data;



    public ResultData(int code, String msg, Integer dataCount, T data){
        this.code = code;
        this.msg = msg;
        this.dataCount = dataCount;
        this.data = data;

    }
    public ResultData(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static <T> ResultData<T> success(){
        return new ResultData<>(CODE_SUCCESSFUL, "成功响应，无返回数据");
    }
    public static <T> ResultData<T> success(String msg,Integer dataCount,T data){
        return new ResultData<>(CODE_SUCCESSFUL,msg,dataCount,data);
    }

    public static <T> ResultData<T> error(String msg){
        return new ResultData<>(CODE_FAILURE,msg);
    }
    public static <T> ResultData<T> error(String msg, T data, Integer dataCount){
        return new ResultData<>(CODE_FAILURE,msg,dataCount,data);
    }

}
